﻿
using Com.Framework.Extension;
using Com.Model.Account;

namespace Com.MVC.Core.Mapper.Account
{
    public class UserInfoMapper : MapperBase<UserInfo, AspNetUser>
    {
        protected override AspNetUser MapInternal(UserInfo source)
        {
            var user = new AspNetUser()
            {
                Id = source.Id,
                UserName = source.UserName,
                PhoneNumber = source.PhoneNumber,
                PhoneNumberConfirmed = source.PhoneNumberConfirmed,

                Email = source.Email,
                EmailConfirmed = source.EmailConfirmed,
                AccessFailedCount = source.AccessFailedCount,
                LockoutEnabled = source.LockoutEnabled,
                TwoFactorEnabled = source.TwoFactorEnabled,
                SecurityStamp = source.SecurityStamp,
                PasswordHash = source.PasswordHash,

                //ApplicationId = source.ApplicationId,
                DisplayName = source.DisplayName,
                MemberId = source.MemberId,
                Recommended = source.Recommended,
                OpenId = source.OpenId,

                //UnitAuthentication = user.UnitAuthentication,
                //PersonalAuthentication = user.PersonalAuthentication,
            };

            if (source.LockoutEndDateUtc.HasValue)
                user.LockoutEndDateUtc = source.LockoutEndDateUtc.Value;
            //if (source.SyncToP2B.HasValue)
            //    user.SyncToP2B = source.SyncToP2B.Value;
            if (source.CreateTime.HasValue)
                user.CreateDate = source.CreateTime.Value;
            if (source.EmailConfirmedExpired.HasValue)
                user.EmailConfirmedExpired = source.EmailConfirmedExpired.Value;
            if (source.EmailConfirmedDate.HasValue)
                user.EmailConfirmedDate = source.EmailConfirmedDate.Value;

            return user;
        }

        protected override UserInfo MapInternal(AspNetUser source)
        {
            var user = new UserInfo()
            {
                Id = source.Id,
                UserName = source.UserName,
                PhoneNumber = source.PhoneNumber,
                PhoneNumberConfirmed = source.PhoneNumberConfirmed,

                Email = source.Email,
                EmailConfirmed = source.EmailConfirmed,
                AccessFailedCount = source.AccessFailedCount,
                LockoutEnabled = source.LockoutEnabled,
                TwoFactorEnabled = source.TwoFactorEnabled,
                SecurityStamp = source.SecurityStamp,
                PasswordHash = source.PasswordHash,

                //ApplicationId = source.ApplicationId,
                DisplayName = source.DisplayName,
                MemberId = source.MemberId,
                Recommended = source.Recommended,
                OpenId = source.OpenId,
                CreateTime = source.CreateDate,
            };

            if (source.LockoutEndDateUtc.HasValue)
                user.LockoutEndDateUtc = source.LockoutEndDateUtc.Value;
            //if (source.SyncToP2B.HasValue)
            //    user.SyncToP2B = source.SyncToP2B.Value;
            if (source.EmailConfirmedExpired.HasValue)
                user.EmailConfirmedExpired = source.EmailConfirmedExpired.Value;
            if (source.EmailConfirmedDate.HasValue)
                user.EmailConfirmedDate = source.EmailConfirmedDate.Value;

            

            return user;
        }
    }
}
